package com;

import java.io.FileInputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.security.KeyStore;

import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManagerFactory;



public class SSLClient {

	public static void main(String[] args) {
		int port = 10080;
		try{
			String key = "C:\\Program Files\\Java\\jdk1.7.0_21\\bin\\SSLKey";
			char [] keyStorePass = "himitsu".toCharArray();
			char [] keyPassword = "himitsu".toCharArray();
			KeyStore keyStore = KeyStore.getInstance("JKS");
			keyStore.load(new FileInputStream(key), keyStorePass);
			TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance("SunX509");
			trustManagerFactory.init(keyStore);
			
			KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
			kmf.init(keyStore,keyPassword);
			
			SSLContext sslContext = SSLContext.getInstance("SSLv3");
			sslContext.init(kmf.getKeyManagers(), trustManagerFactory.getTrustManagers(), null);
			SSLSocketFactory socketFactory = sslContext.getSocketFactory();
			Socket socket = socketFactory.createSocket("localhost", port);
			OutputStream out = socket.getOutputStream();
			out.write("Client say hello".getBytes());
			out.flush();
			out.close();
			socket.close();
		}catch (Exception e) {
			e.printStackTrace();
		}
	}

}
